package jp.test;



import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JSplitPane;
import javax.swing.JTextField;

public class GatewayControlPanelPane extends JPanel implements MouseListener {

	public void mouseClicked(MouseEvent arg0) {
		// TODO Auto-generated method stub
		String text = this.textField1.getText();
		System.out.println("text="+text);
		gateway.connectDA(text);
	}

	public void mouseEntered(MouseEvent arg0) {
		// TODO Auto-generated method stub

	}

	public void mouseExited(MouseEvent arg0) {
		// TODO Auto-generated method stub

	}

	public void mousePressed(MouseEvent arg0) {
		// TODO Auto-generated method stub

	}

	public void mouseReleased(MouseEvent arg0) {
		// TODO Auto-generated method stub

	}
	
	public static int DEFAULT_WIDTH = 640;
	public final static int DEFAULT_HEIGHT = 480;
	
	private TreeComp deviceTree;
	private TreeComp worldTree;
	private JSplitPane devSplitPane;
	private JTextField textField1 ;
	
	private Gateway gateway;
	
	public void setGateway(Gateway gw){
		this.gateway = gw;
	}
	
	public GatewayControlPanelPane(){
		setLayout(new BorderLayout());
		
		TreeNode root = new TreeNode("Avaliable Devices in Network");
		TreeNode world = new TreeNode("World");
		
		JSplitPane mainSplitPan = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, false);
		add(mainSplitPan, BorderLayout.CENTER);
		
		devSplitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, false);
		mainSplitPan.setRightComponent(devSplitPane);
		
		// Device Tree
		deviceTree = new TreeComp(root);
		deviceTree.addMouseListener(this);
		JScrollPane devScrollPane = new JScrollPane(deviceTree);
		devScrollPane.setPreferredSize(new Dimension(DEFAULT_WIDTH/3,DEFAULT_HEIGHT));
		mainSplitPan.setLeftComponent(devScrollPane);
		
		worldTree = new TreeComp(world);
		worldTree.addMouseListener(this);
		JScrollPane worldScrollPane = new JScrollPane(worldTree);
		worldScrollPane.setPreferredSize(new Dimension((DEFAULT_WIDTH/2)*2,DEFAULT_HEIGHT/4));
		devSplitPane.setTopComponent(worldTree);
				
		JLabel label1 = new JLabel();
		label1.setText("Enter Host Name");
		label1.setHorizontalAlignment(JLabel.LEFT);
		label1.setVerticalAlignment(JLabel.TOP);
		
		textField1 =new JTextField();

		
		
		JButton but1 = new JButton("Join");
		but1.addMouseListener(this);
		

				
		JPanel p2 = new JPanel();
		p2.setLayout(new BoxLayout(p2, BoxLayout.Y_AXIS));
	
		p2.add(label1);
		p2.add(textField1);
		p2.add(but1);

			
		devSplitPane.setBottomComponent(p2);

	}

}
